package com.work.dao.impl;

import com.work.bean.Message;
import com.work.bean.Notice;
import com.work.dao.BaseDao;
import com.work.dao.MessageDao;

import java.util.List;

public class MessageDaoImpl extends BaseDao implements MessageDao {
    @Override
    public List<Message> queryMessage() {
        String sql = "SELECT * FROM t_message";
        return queryForList(Message.class,sql);
    }

    @Override
    public Message queryMessageById(Integer id) {
        String sql = "SELECT * FROM t_message WHERE id = ?";
        return queryForOne(Message.class,sql,id);
    }

    @Override
    public int saveMessage(Message message) {
        String sql = "INSERT INTO `t_message` (`title`,`content`,`s_id`,`t_id`,`time`,`state`)VALUE(?,?,?,?,?,?)";
        return update(sql,message.getTitle(),message.getContent(),message.getS_id(),message.getT_id(),message.getTime(),message.getState());
    }

    @Override
    public int updateMessage(Integer id, Integer status) {
        String sql = "UPDATE  `t_message` SET `state` = ? WHERE `id` = ?";
        return update(sql,status,id);
    }

    @Override
    public int deleteMessage(Integer id) {
        String sql = "DELETE FROM `t_message` WHERE `id` = ?";
        return update(sql,id);
    }

    @Override
    public List<Message> queryMessageBytId(Integer t_id) {
        String sql = "SELECT * FROM t_message WHERE t_id = ? ";
        return queryForList(Message.class,sql,t_id);
    }

    @Override
    public Message queryMessageBysId(Integer s_id) {
        String sql = "SELECT * FROM t_message WHERE s_id = ? ";
        return queryForOne(Message.class,sql,s_id);
    }
}
